package com.huluobo.lc.videopagedemo1806a;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.jzvd.JzvdStd;

/**
 * @author Lc
 * @description:
 * @date :2020/11/23 14:12
 */
public class VideoPageAdapter extends RecyclerView.Adapter<VideoPageAdapter.VideoViewHolder> {
    private Context context;
    private List<String> list;

    public VideoPageAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public VideoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new VideoViewHolder(LayoutInflater.from(context).inflate(R.layout.item_video_page,
                parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) {
        holder.jz_video.setUp(list.get(position), String.format("第%d个视频", position + 1),
                JzvdStd.STATE_NORMAL);
        if (position==0){
            holder.jz_video.startVideo();
        }
        Glide.with(context).load(list.get(position)).into(holder.jz_video.thumbImageView);
    }

    @Override
    public int getItemCount() {
        return Math.max(list.size(), 0);
    }

    public static class VideoViewHolder extends RecyclerView.ViewHolder {
        public JzvdStd jz_video;

        public VideoViewHolder(@NonNull View itemView) {
            super(itemView);
            jz_video = itemView.findViewById(R.id.jz_video);
        }
    }
}
